import axios from 'axios';
// 创建 axios 实例
const service = axios.create({
  baseURL: import.meta.env.VITE_APP_BASE_API,
  timeout: 50000,
  headers: { 'Content-Type': 'application/json;charset=utf-8' }
});
    // 请求拦截器
    service.interceptors.request.use(
        (config) => {
        return config;
        },
        (error: any) => {
        return Promise.reject(error);
        }
    );
  
  // 响应拦截器
  service.interceptors.response.use(
    (response) => {
      const { status, msg } = response.data;
      if (status === 0) {
        return response.data;
      } else {
        // 响应数据为二进制流处理(Excel导出)
        if (response.data instanceof ArrayBuffer) {
          return response;
        }
        return Promise.reject(new Error(msg || 'Error'));
      }
    },
    (error: any) => {
      if (error.response.data) {}
      return Promise.reject(error.message);
    }
  );
  
  // 导出 axios 实例
  export default service;